<?php
/**
 * 目标抽象类
 *
 * @author iwind <iwind.iwind@gmail.com>
 * @link http://www.4kiki.net/
 * @version $Id: IAbstractSubject.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.observer
 */

/**
 * 目标抽象类
 *
 * @version $Id: IAbstractSubject.php 312 2008-04-23 16:29:38Z iwind $
 * @package net.4kiki.observer
 */
abstract class IAbstractSubject implements ISubject {
	private $observers = array();
	
	public function attach(IObserver $observer) {
		$this->observers[] = $observer;	
	}
	
	public function detach(IObserver $observer) {
		$keys = array_keys($this->observers, $observer);
		if (!empty($keys)) {
			foreach ($keys as $key) {
				unset($this->observers[$key]);
			}
		}
	}
	
	public function notify() {
		foreach ($this->observers as $observer) {
			$observer->update($this);
		}
	}
}

?>